local ruliu = fk.CreateSkill {
  name = "lingling__ruliu",
}

Fk:loadTranslationTable{
  ["lingling__ruliu"] = "如流",
  [":lingling__ruliu"] = "当其他角色对你使用锦囊牌结算后，你可以将之置于牌堆底，若此牌为黑色且你手牌不为最多，你摸一张牌。",

  ["#lingling__ruliu-invoke"] = "如流：是否将%arg置于牌堆底？",
}

ruliu:addEffect(fk.CardUseFinished, {
  anim_type = "control",
  can_trigger = function (self, event, target, player, data)
    return target ~= player and player:hasSkill(ruliu.name) and
      data.card.type == Card.TypeTrick and table.contains(data.tos, player) and
      table.contains({Card.Processing, Card.PlayerJudge}, player.room:getCardArea(data.card))
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askToSkillInvoke(player, {
      skill_name = ruliu.name,
      prompt = "#lingling__ruliu-invoke:::"..data.card:toLogString(),
    })
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:moveCards {
      ids = Card:getIdList(data.card),
      from = room:getCardOwner(data.card),
      toArea = Card.DrawPile,
      moveReason = fk.ReasonJustMove,
      skillName = ruliu.name,
      proposer = player,
      moveVisible = true,
      drawPilePosition = -1
    }
    if not player.dead and data.card.color == Card.Black and
      table.find(room.alive_players, function (p)
        return p:getHandcardNum() > player:getHandcardNum()
      end) then
      player:drawCards(1, ruliu.name)
    end
  end,
})

return ruliu
